if myHero.charName ~= "Blitzcrank" then return end

require "Prodiction"

local QRange = 1050
local RRange = 600

local Prodict = ProdictManager.GetInstance()
local ProdictQ
local ProdictQCollision
function PluginOnLoad()

	
	ProdictQ = Prodict:AddProdictionObject( _Q, QRange, 1800, 0.25, 90 )
	ProdictQCollision = Collision( QRange, 1800, 0.25, 90 )
		
	if myHero:GetSpellData(SUMMONER_1).name:find("SummonerDot") then
		igniteslot = SUMMONER_1
	elseif myHero:GetSpellData(SUMMONER_2).name:find("SummonerDot") then
		igniteslot = SUMMONER_2
	end
	
	AutoCarry.SkillsCrosshair.range = 1050
	
	Menu = AutoCarry.PluginMenu
	Menu:addParam("qGrab","Grab", SCRIPT_PARAM_ONOFF, true)
	Menu:addParam("wCombo","W in Combo", SCRIPT_PARAM_ONOFF, true)
	Menu:addParam("eCombo","E in Combo", SCRIPT_PARAM_ONOFF, true)
	Menu:addParam("uks","R KillsSteal", SCRIPT_PARAM_ONOFF, true)
	Menu:addParam("autoig","Auto Ignite", SCRIPT_PARAM_ONOFF, true)
	
	
	PrintChat(">> Blitzcrank with Prodiction v0.02 loaded")
end
function UltKillSteal()
	if RAble then
		for _, entity in pairs(GetEnemyHeroes()) do
			if ValidTarget( entity, RRange ) then
				if getDmg( "R", entity, myHero ) >= entity.health then
					CastSpell(_R)
				end
			end
		end
	end
end
function PluginOnTick()

	AutoIgnite()
	
	QAble = (myHero:CanUseSpell(_Q) == READY)
	WAble = (myHero:CanUseSpell(_W) == READY)
	EAble = (myHero:CanUseSpell(_E) == READY)
	RAble = (myHero:CanUseSpell(_E) == READY)
	Target = AutoCarry.GetAttackTarget()
	
	if Menu.uks then
		UltKillSteal()
	end
	
	if Target and AutoCarry.MainMenu.AutoCarry then
		if GetDistance(Target) < QRange then
			if GetDistance(Target) > 125 then
				if QAble then
					ProdictQ:GetPredictionCallBack(Target,CastQ)
				end
			elseif GetDistance(Target) <= 125 then
				if EAble and Menu.eCombo then
					CastSpell(_E)
				end
				if WAble and Menu.wCombo then
					CastSpell(_W)
				end
			end
		end
	end
end

function PluginOnDraw()
    if not myHero.dead then
		if Target then
			ProdictQCollision:DrawCollision(myHero, Target)
		end
		DrawCircle(myHero.x, myHero.y, myHero.z, QRange, 0xFFFFFF)
	end
	
end

local function getHitBoxRadius(target)
	return GetDistance(target, target.minBBox)
end

function CastQ(unit, pos)
	if GetDistance(pos) - getHitBoxRadius(unit)/2 < QRange then
		local Hit = ProdictQCollision:GetMinionCollision(pos, myHero)
		if not Hit then
			CastSpell(_Q, pos.x, pos.z)
		end
	end
end
	
function AutoIgnite( )
    for _, igtarget in pairs(GetEnemyHeroes()) do
		if ValidTarget(igtarget, 600) and autoig and igtarget.health <= 50 + (20 * player.level) then
        	CastSpell(igniteslot, igtarget)
        end
    end
end